
//店铺数据模块
import {getShopSellerReq,getGoodsListReq} from '@/api/shop'
const state = {
  shopData: {},
  goodsList:[],//存放数据
}

const mutations = {
  SET_SHOPINFO(state, data) {
    state.shopData = data
  },
  SET_GOODS_LIST(state,data){
    state.goodsList=data
  }
}
const getters={
  navList(state){
    return state.goodsList.map(v=>v.name)
  }
}


const actions = {
  //获取店铺数据
  A_getShopInfo({commit}) {
    return new Promise(async resolve => {
      let res = await getShopSellerReq()
      //解构数据
      let {data} = res.data
      //数据赋值
      commit('SET_SHOPINFO', data)
    })
  },
    //获取商品列表数据  
    A_getGoodsData({commit}){
      return new Promise(async resolve=>{
        //发送请求
        let res =await getGoodsListReq()
        //结构数据
        let {code,data}=res.data

            if(code===0){
                commit('SET_GOODS_LIST',data)
                resolve()
            }
      })
    }

}

export default {
  namespaced: true,
  state,
  mutations,
  getters,
  actions,
}
